home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-13 / thesrc10.zip / MANEXT.C < prev    next >
C/C++ Source or Header  |  1992-08-08  |  5KB  |  157 lines

  1. /***********************************************************************/
  2. /* MANEXT - Extract manual pages from C source code.                   */
  3. /***********************************************************************/
  4. /*
  5.  * MANEXT - A program to extract manual pages from C source code.
  6.  * Copyright (C) 1991,1992 Mark Hessling
  7.  *
  8.  * This program is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU General Public License as
  10.  * published by the Free Software Foundation; either version 2 of
  11.  * the License, or any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16.  * General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to:
  20.  *
  21.  *    The Free Software Foundation, Inc.
  22.  *    675 Mass Ave,
  23.  *    Cambridge, MA 02139 USA.
  24.  *
  25.  *
  26.  * If you make modifications to this software that you feel increases
  27.  * it usefulness for the rest of the community, please email the
  28.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  29.  * This software is going to be maintained and enhanced as deemed
  30.  * necessary by the community.
  31.  *
  32.  * Mark Hessling                     email: M.Hessling@itc.gu.edu.au
  33.  * 36 David Road                     Phone: +61 7 849 7731
  34.  * Holland Park                      Fax:   +61 7 875 7877
  35.  * QLD 4121
  36.  * Australia
  37.  */
  38. #include <stdio.h>
  39.  
  40. void display_info();
  41.  
  42. /*---------------------------------------------------------------------*/
  43. /* Following are for getopt function(s).                               */
  44. /*---------------------------------------------------------------------*/
  45. extern char *optarg;
  46. extern int optind;
  47.  
  48. #define MAX_LINE 255
  49.  
  50. /***********************************************************************/
  51. int main(argc,argv)
  52. int argc;
  53. char *argv[];
  54. /***********************************************************************/
  55. {
  56.  char    s[MAX_LINE + 1];        /* input line */
  57.  register int     i = 0;
  58.  FILE *fp,*fpo;
  59.  char outfile[MAX_LINE+1];
  60.  char c;
  61.  strcpy(outfile,"");
  62.  
  63.  while ((c = getopt(argc,argv,"h?o:")) != (-1))
  64.    switch(c)
  65.      {
  66.       case 'o':        /* profile file name */
  67.            strcpy(outfile,optarg);
  68.            break;
  69.       default:
  70.                display_info();
  71.            exit(1);
  72.            break;
  73.      }
  74.  if (strcmp(outfile,"") == 0)
  75.    {
  76.     fprintf(stderr,"\nNo output file name specified\n");
  77.     exit(1);
  78.    }
  79.  
  80.  if ((fpo = fopen(outfile,"w")) == NULL)
  81.    {
  82.     fprintf(stderr,"\nCould not open %s for output\n",outfile);
  83.     exit(1);
  84.    }
  85.  
  86.  while(optind<argc)
  87.     {
  88.      if ((fp = fopen(argv[optind],"r")) == NULL)
  89.        {
  90.         fprintf(stderr,"\nCould not open %s\n",argv[optind]);
  91.         continue;
  92.        }
  93.      while(1)
  94.        {
  95.         if (fgets(s, (int)sizeof(s), fp) == NULL)
  96.           {
  97.        if (ferror(fp) != 0)
  98.              {
  99.               fprintf(stderr, "*** Error reading %s.  Exiting.\n",argv[optind]);
  100.               exit(1);
  101.              }
  102.        break;
  103.           }
  104.  
  105.         /* check for manual entry marker at beginning of line */
  106.         if (strncmp(s, "/*man-start*", 12) != 0)
  107.             continue;
  108.  
  109.         /* inner loop */
  110.         for (;;)
  111.            {
  112.             /* read next line of manual entry */
  113.         if (fgets(s, (int)sizeof(s), fp) == NULL)
  114.               {
  115.            if (ferror(fp) != 0)
  116.          {
  117.           fprintf(stderr, "*** Error reading %s.  Exiting.\n",argv[optind]);
  118.           exit(1);
  119.          }
  120.         break;
  121.           }
  122.         /* check for end of entry marker */
  123.         if (strncmp(s, "**man-end", 9) == 0)
  124.            break;
  125.  
  126.         fprintf(fpo,"     %s",s);
  127.             }
  128.     fputs("\n\n\n     --------------------------------------------------------------------------\n", fpo);
  129.  
  130.         /* check if end of file */
  131.         if (feof(fp) != 0)
  132.             break;
  133.        }
  134.      fclose(fp);
  135.      optind++;
  136.     }
  137.  fputs("\n\n\n\n\n", fpo);
  138.  fclose(fpo);
  139.  return(0);
  140. }
  141. /***********************************************************************/
  142. void display_info()
  143. /***********************************************************************/
  144. {
  145. /*--------------------------- local data ------------------------------*/
  146. /*--------------------------- processing ------------------------------*/
  147.  
  148.  fprintf(stderr,"\nMANEXT 1.00 Copyright (C) 1991,1992 Mark Hessling\n");
  149.  fprintf(stderr,"All rights reserved.\n");
  150.  fprintf(stderr,"MANEXT is distributed under the terms of the GNU\n");
  151.  fprintf(stderr,"General Public License and comes with NO WARRANTY.\n");
  152.  fprintf(stderr,"See the file COPYING for details.\n");
  153.  fprintf(stderr,"\nUsage: MANEXT -o outfilename sourcefile [...]\n\n");
  154.  fflush(stderr);
  155.  return;
  156. }
  157.